//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LitwareHR.PublicApp.Presenters.Careers.Recruiting;
using LitwareHR.Recruiting.Contract;
using System.Threading;
using System.Globalization;
using Resources;

public partial class Careers_Recruiting_Resume : BasePage, IResumeView
{
    ResumePresenter _presenter;

    public ResumePresenter Presenter
    {
        get
        {
            return _presenter;
        }
    }

    protected override void OnInitComplete(EventArgs e)
    {
        base.OnInitComplete(e);
        _presenter = new ResumePresenter(this);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies[Constants.PositionCookie] == null)
            throw new ArgumentNullException(Constants.PositionCookie);
        string positionId = Request.Cookies[Constants.PositionCookie].Value;
        if (string.IsNullOrEmpty(positionId))
            throw new ArgumentNullException(Constants.PositionCookie);

        _presenter.OnViewLoaded();
    }

    public void SetValidators()
    {
        string minValue = DateTime.MinValue.ToShortDateString();
        string maxValue = DateTime.Now.ToShortDateString();

        ExperienceStartDateRange.MaximumValue = maxValue;
        ExperienceStartDateRange.MinimumValue = minValue;
        ExperienceEndDateRange.MaximumValue = maxValue;
        ExperienceEndDateRange.MinimumValue = minValue;
        EducationStartDateRange.MaximumValue = maxValue;
        EducationStartDateRange.MinimumValue = minValue;
        EducationEndDateRange.MaximumValue = maxValue;
        EducationEndDateRange.MinimumValue = minValue;
    }

    public void SetDefaultValues()
    {
        string datePattern = Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern;
        ExperienceStartDateFormatLabel.Text = datePattern;
        ExperienceEndDateFormatLabel.Text = datePattern;
        EducationStartDateFormatLabel.Text = datePattern;
        EducationEndDateFormatLabel.Text = datePattern;

        string value = DateTime.Now.ToShortDateString();
        ExperienceStartDateTextBox.Text = value;
        ExperienceEndDateTextBox.Text = value;
        EducationStartDateTextBox.Text = value;
        EducationEndDateTextBox.Text = value;
    }

    protected void SubmitButton_Click(object sender, EventArgs e)
    {
        if (Request.Cookies[Constants.PositionCookie] == null)
            throw new ArgumentNullException(Constants.PositionCookie);
        string positionId = Request.Cookies[Constants.PositionCookie].Value;
        if (string.IsNullOrEmpty(positionId))
            throw new ArgumentNullException(Constants.PositionCookie);

        Page.Validate();

        if (Page.IsValid)
        {
            Resume resume = new Resume();
            resume.PositionId = new Guid(positionId);
            
            _presenter.OnSubmit(resume);
            string redirect = ConfigurationManager.AppSettings[Constants.RecruitingHome];
            Response.Redirect(redirect);
        }
    }
}
